﻿Option Explicit On
Option Strict On

''' <summary>
''' Formulario Borrar Cita: Para borrar citas de la BBDD
''' </summary>
''' <author>Héctor Pastor</author>

Public Class BorrarCita
    Private listaCitas As List(Of Cita)
    Private miBBDD As BBDD

    Private Sub BorrarCita_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        miBBDD = New BBDD
        listaCitas = New List(Of Cita)
        ActualizaFormulario()
    End Sub

    Private Sub Eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btEliminar.Click
        'Eliminar el campo seleccionado en la tabla
        miBBDD.Conectar()
        miBBDD.BorraCita(CInt(dgvListaCitas.CurrentRow.Cells(1).Value))
        miBBDD.Desconectar()
        ActualizaFormulario()
    End Sub

    Private Sub ActualizaFormulario()
        dgvListaCitas.Rows.Clear()
        miBBDD.Conectar()
        listaCitas = miBBDD.ListaCitas("Select * from cita")
        miBBDD.Desconectar()
        For Each citaUnica As Cita In listaCitas
            dgvListaCitas.Rows.Add(citaUnica.Fecha.ToString("hh:mm"), citaUnica.Codigo, citaUnica.CodigoCliente, citaUnica.CodigoUsuario, citaUnica.Recordatorio)
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCancelar.Click
        Me.Close()
    End Sub
End Class